<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Cate extends Model
{
    /**
     * 创建分类
     * @param $request \Request 请求数据
     * @return bool
     * */
    public function create($request)
    {
        $this->name = $request->name;
        $this->user_name = $request->user_name;
        $this->user_id = $request->user_id;
        $this->description  = $request->description;
        return $this->save();
    }

    /**
     * 查询列表并分页
     * @param int $page 每页显示数据数量
     * @param array $condition 查询条件
     * @return object
     * */
    public function getList($page, array $condition = [])
    {
        return $this->where($condition)->paginate($page);
    }

    /*
     * 查询全部分类名称
     * */
    public function getCateSerialize($ids)
    {
        $cates = self::find($ids)->toArray();
        $cates = serialize($cates);
        return $cates;
    }

    public function del($id)
    {
        return self::destroy($id);
    }

}
